package com.engine4cloud.tdf.supervision.controller.web;

import cn.hutool.core.collection.CollUtil;
import com.engine4cloud.tdf.common.core.util.R;
import com.engine4cloud.tdf.common.data.web.response.PageInfo;
import com.engine4cloud.tdf.common.data.web.response.Params;
import com.engine4cloud.tdf.common.log.annotation.SysLog;
import com.engine4cloud.tdf.supervision.dto.create.SpAccessSpecificCreateDTO;
import com.engine4cloud.tdf.supervision.dto.query.SpAccessSpecificQueryDTO;
import com.engine4cloud.tdf.supervision.dto.result.SpAccessSpecificResultDTO;
import com.engine4cloud.tdf.supervision.dto.update.SpAccessSpecificUpdateDTO;
import com.engine4cloud.tdf.supervision.service.SpAccessSpecificService;
import io.swagger.v3.oas.annotations.Operation;
import io.swagger.v3.oas.annotations.security.SecurityRequirement;
import io.swagger.v3.oas.annotations.tags.Tag;
import jakarta.validation.Valid;
import lombok.RequiredArgsConstructor;
import org.springdoc.core.annotations.ParameterObject;
import org.springframework.http.HttpHeaders;
import org.springframework.security.access.prepost.PreAuthorize;
import org.springframework.web.bind.annotation.*;

/**
 * 进入特定区域
 *
 * @author wenjie
 * @date 2024-05-31 10:24:42
 */
@RestController
@RequiredArgsConstructor
@RequestMapping("/web/access/specific")
@Tag(description = "AccessSpecific", name = "审批-进入特定区域管理-web")
@SecurityRequirement(name = HttpHeaders.AUTHORIZATION)
public class SpAccessSpecificWebController {

    private final SpAccessSpecificService accessSpecificService;

    /**
     * 分页查询
     *
     * @param page 分页对象
     * @param dto  进入特定区域
     * @return R<PageInfo < RcglInvestigateResultDTO>>
     */
    @Operation(summary = "分页查询", description = "分页查询")
    @GetMapping("/page")
    public R<PageInfo<SpAccessSpecificResultDTO>> getPageList(@ParameterObject Params page, @Valid @ParameterObject SpAccessSpecificQueryDTO dto) {
        return R.ok(accessSpecificService.getPageList(page, dto));
    }


    /**
     * 通过id查询进入特定区域
     *
     * @param id id
     * @return R
     */
    @Operation(summary = "通过id查询", description = "通过id查询")
    @GetMapping("/{id}")
    public R<SpAccessSpecificResultDTO> getById(@PathVariable("id") Long id) {
        return R.ok(accessSpecificService.getById(id));
    }

    /**
     * 新增进入特定区域
     *
     * @param dto 进入特定区域
     * @return R
     */
    @Operation(summary = "新增进入特定区域", description = "新增进入特定区域")
    @SysLog("新增进入特定区域")
    @PostMapping
    @PreAuthorize("@pms.hasPermission('access_specific_add')")
    public R<Boolean> create(@Valid @RequestBody SpAccessSpecificCreateDTO dto) {
        return R.ok(accessSpecificService.create(dto));
    }

    /**
     * 修改进入特定区域
     *
     * @param dto 进入特定区域
     * @return R
     */
    @Operation(summary = "修改进入特定区域", description = "修改进入特定区域")
    @SysLog("修改进入特定区域")
    @PutMapping
    @PreAuthorize("@pms.hasPermission('access_specific_edit')")
    public R<Boolean> update(@Valid @RequestBody SpAccessSpecificUpdateDTO dto) {
        return R.ok(accessSpecificService.update(dto));
    }

    /**
     * 通过id删除进入特定区域
     *
     * @param ids id列表
     * @return R
     */
    @Operation(summary = "通过id删除进入特定区域", description = "通过id删除进入特定区域")
    @SysLog("通过id删除进入特定区域")
    @DeleteMapping
    @PreAuthorize("@pms.hasPermission('access_specific_del')")
    public R<Boolean> removeById(@RequestBody Long[] ids) {
        return R.ok(accessSpecificService.removeBatchByIds(CollUtil.toList(ids)));
    }
}